<?php
namespace app\index\controller;

use app\common\controller\Front;

class Dub extends Front
{
    protected function initialize()
    {
        $this->auth['check'] = true;

        $this->auth['cancel_login'] = ['index/dub/index'];
        
        $this->auth['cancel_limit'] = '*';

        $this->auth['redirect_url'] = dcUrl('index/dub/index');
        
        parent::initialize(); 
    }

    public function index()
    {
        $this->site['historyGo'] = dcUrl('index/index/index');
        
        $this->assign(config('dub.'));

        $this->assign($this->site);

        return $this->fetch();
    }

    public function save()
    {
        //积分验证
        if(config('dub.score')){
            $this->scoreValidate(config('dub.score'));
        }
        //文本解析
        $text = dcMarkdownParse(input('post.text/s'));
        if(!$text){
            $this->error('格式错误');
        }
        //积分扣除
        if(config('dub.score')){
            model('common/Score','loglic')->decApps($this->user['user_id'], config('dub.id'), config('dub.score'), config('dub.name'));
        }
        //模板定义
        $this->assign('text',$text);
        $this->assign(config('dub.'));
        $this->assign($this->site);
        return $this->fetch();
    }
}